package com.course.system.controller.admin;

import com.course.server.dto.PageDto;
import com.course.server.dto.ResourceDto;
import com.course.server.dto.ResponseDto;
import com.course.server.service.ResourceService;
import com.course.server.util.ValidatorUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
* @author TangKe（唐柯）
* @date
*/
@RestController
@RequestMapping("/admin/resource")
public class ResourceController {

private static final Logger LOG = LoggerFactory.getLogger(ResourceController.class);
public static final String BUSINESS_NAME = "资源";

@Resource
private ResourceService resourceService;


/**
* 列表查询
*/
@PostMapping("/list")
public ResponseDto list(@RequestBody  PageDto pageDto){

LOG.info("pageDto:{}",pageDto);
ResponseDto responseDto = new ResponseDto();
resourceService.list(pageDto);
responseDto.setContent(pageDto);
return responseDto;
}


/**
* 保存，id有值时更新，无值时新增
*/

@PostMapping("/save")
public ResponseDto save(@RequestBody String jsonSte){



           //保存校验
            ValidatorUtil.require(jsonSte,"资源");

            ResponseDto responseDto = new ResponseDto();
            resourceService.saveJson(jsonSte);
            return responseDto;
}


/**
* 删除
*/
@DeleteMapping("/delete/{id}")
public ResponseDto delete(@PathVariable String id){


ResponseDto responseDto = new ResponseDto();
resourceService.delete(id);

return  responseDto;
}


    /**
     * 资源树查询
     * @return
     */
 @GetMapping("/load-tree")
  public  ResponseDto loadTree(){

     ResponseDto responseDto = new ResponseDto();
      List<ResourceDto> responseDtoList  = resourceService.loadTree();
      responseDto.setContent(responseDtoList);
      return responseDto;


 }



}
